package com.yadong.demo01;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class BeanPostProcessor3 implements SmartInstantiationAwareBeanPostProcessor {

	@Override
	public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
		if(beanName.equals("bean1")){
			Bean1 bean1 = new Bean1("替换后的对象bean1");
			Bean2 bean2 = new Bean2("替换后的对象bean1.bean2");
			bean1.setBean2(bean2);
			return bean1;
		}else{
			return bean;
		}
	}

}
